import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import moment from 'moment';
import {fetch, patch, post, put} from './api/Api';
import Storage from 'vue-ls';

Vue.use(ElementUI);

Vue.prototype.$moment = moment;

//定义全局变量
Vue.prototype.$post = post;
Vue.prototype.$fetch = fetch;
Vue.prototype.$patch = patch;
Vue.prototype.$put = put;


let options = {
    namespace: 'vue__', // key键前缀
    name: 'ls', // 命名Vue变量.[store]或this.[$store],
    storage: 'local', // 存储名称: session, local, memory
};
Vue.use(Storage, options);


Vue.config.productionTip = false;

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app');

Vue.prototype.$merchantStatus = [
    {'label': '审核中', 'value': 'APPROVING'},
    {'label': '已审核', 'value': 'APPROVED'},
    {'label': '审核不通过', 'value': 'REJECTED'}
];
Vue.prototype.$withDrawApplyStatus = [
    {'label': '审核中', 'value': 'APPROVING'},
    {'label': '已完成', 'value': 'COMPLETED'},
    {'label': '已拒绝', 'value': 'REJECTED'}
];
Vue.prototype.$billType = [
    {'label': '出售收入', 'value': 'SELL_INCOME'},
    {'label': '租赁租金', 'value': 'LEASE_INCOME'},
    {'label': '收到租赁押金', 'value': 'LEASE_DEPOSIT'},
    {'label': '给客户退款', 'value': 'REFUND_OUTGOING'},
    {'label': '提现', 'value': 'WITHDRAW'},
    {'label': '其他', 'value': 'OTHER'},
];
Vue.prototype.$orderType = [
    {'label': '购买', 'value': 'BUY'},
    {'label': '租赁', 'value': 'LEASE'},
];
Vue.prototype.$deliveryStatus = [
    {'label': '未签收', 'value': 'UNDELIVERED'},
    {'label': '已签收', 'value': 'DELIVERED'},
    {'label': '已取消', 'value': 'CANCELLED'},
];
Vue.prototype.$deliveryType = [
    {'label': '购买发货', 'value': 'CLIENT_BUY_FROM_MERCHANT'},
    {'label': '租赁发货', 'value': 'CLIENT_LEASE_FROM_MERCHANT'},
    {'label': '退货', 'value': 'CLIENT_RETURN_FROM_CLIENT'},
    {'label': '换货', 'value': 'CLIENT_EXCHANGE_FROM_CLIENT'},
    {'label': '重新发货', 'value': 'CLIENT_EXCHANGE_FROM_MERCHANT'},
];
Vue.prototype.$logisticsType = [
    {'label': '物流快递', 'value': 'LOGISTICS'},
    {'label': '客户到附近营业网点自提', 'value': 'CLIENT_SELF_PICKUP'},
    {'label': '商家配送上门', 'value': 'MERCHANT_SEND'},
    {'label': '客户送货到附近网点', 'value': 'CLIENT_SEND_NEARBY_SITE'},
],
Vue.prototype.$orderStatus = [
    {'label': '生效中', 'value': 'EFFECTIVE'},
    {'label': '已失效', 'value': 'INVALID'},
];
Vue.prototype.$payStatus = [
    {'label': '未支付', 'value': 'UN_PAID'},
    {'label': '已支付', 'value': 'PAID'},
];
Vue.prototype.$exchangeApplyStatus = [
    {'label': '待商户审核', 'value': 'APPROVING'},
    {'label': '商户已审核', 'value': 'APPROVED'},
    {'label': '商户已拒绝', 'value': 'REJECTED'},
    {'label': '客户已发货', 'value': 'CLIENT_DELIVERED'},
    {'label': '商户已确认收货', 'value': 'MERCHANT_CONFIRMED'},
    {'label': '客户已确认收货', 'value': 'CLIENT_CONFIRMED'},
    {'label': '商户已退款', 'value': 'MERCHANT_REFUNDED'},
];
Vue.prototype.$returnApplyStatus = [
    {'label': '待商户审核', 'value': 'APPROVING'},
    {'label': '商户已审核', 'value': 'APPROVED'},
    {'label': '商户已拒绝', 'value': 'REJECTED'},
    {'label': '客户已发货', 'value': 'CLIENT_DELIVERED'},
    {'label': '商户已确认收货', 'value': 'MERCHANT_CONFIRMED'},
    {'label': '商户已退款', 'value': 'MERCHANT_REFUNDED'},
];
Vue.filter('merchantStatusText', val => Vue.prototype.$merchantStatus.find(item => item.value === val).label);
Vue.filter('withDrawApplyStatusText', val => Vue.prototype.$withDrawApplyStatus.find(item => item.value === val).label);
Vue.filter('billTypeText', val => Vue.prototype.$billType.find(item => item.value === val).label);
Vue.filter('orderTypeText', val => Vue.prototype.$orderType.find(item => item.value === val).label);
Vue.filter('deliveryStatusText', val => Vue.prototype.$deliveryStatus.find(item => item.value === val).label);
Vue.filter('logisticsTypeText', val => Vue.prototype.$logisticsType.find(item => item.value === val).label);
Vue.filter('orderStatusText', val => Vue.prototype.$orderStatus.find(item => item.value === val).label);
Vue.filter('payStatusText', val => Vue.prototype.$payStatus.find(item => item.value === val).label);
Vue.filter('exchangeApplyStatusText', val => Vue.prototype.$exchangeApplyStatus.find(item => item.value === val).label);
Vue.filter('returnApplyStatusText', val => Vue.prototype.$returnApplyStatus.find(item => item.value === val).label);
Vue.filter('deliveryTypeText', val => Vue.prototype.$deliveryType.find(item => item.value === val).label);
Vue.filter('yuan', str => cny.yuan(str));

export const cny = {
    yuan: fen => fen ? (parseInt(fen) / 100).toFixed(2) : 0,
    fen: yuan => yuan ? Math.round(parseFloat(yuan) * 100) : 0
};

export const yuanToFen = (val) => {
    if (val) {
        val = typeof val === 'string' ? val : JSON.stringify(val);
        var s = val.split(".");
        var yuan = parseInt(s[0]) * 100;
        var fen = 0;
        if (s.length > 1) {
            let fenVal = (parseInt(s[1].substr(0, 1))) * 10;
            fen += fenVal;
            if (s[1].length > 1) {
                fen += parseInt(s[1].substr(1, 1));
            }
        }
        var fee = yuan + fen;
        return fee
    }
};